package com.example.myapplication5;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private List<Mobilephone> phoneList=new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initPhone();
        MobileAdapter mobileAdapter=new MobileAdapter(MainActivity.this,R.layout.phone_order,phoneList);
        ListView listView=(ListView) findViewById(R.id.list_view);
        listView.setAdapter(mobileAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Mobilephone pho=phoneList.get(i);
                Intent intent=new Intent(MainActivity.this, ItemDetailAcidity.class);
                intent.putExtra("info",pho.getInfo()+"");
                startActivity(intent);

            }
        });
    }
    private void initPhone(){
        Mobilephone one=new Mobilephone(1,"联想",510947);
        phoneList.add(one);
        Mobilephone two=new Mobilephone(2,"戴尔",225193);
        phoneList.add(two);
        Mobilephone three=new Mobilephone(3,"华硕",222513);
        phoneList.add(three);
       Mobilephone four=new Mobilephone(4,"苹果",181891);
        phoneList.add(four);
        Mobilephone five=new Mobilephone(5,"惠普",91470);
        phoneList.add(five);
        Mobilephone six=new Mobilephone(6,"宏基",72139);
        phoneList.add(six);
        Mobilephone sevent=new Mobilephone(7,"索尼",64158);
        phoneList.add(sevent);
        Mobilephone eight=new Mobilephone(8,"三星",52514);
        phoneList.add(eight);
        Mobilephone nine=new Mobilephone(9,"神舟",35647);
        phoneList.add(nine);
        Mobilephone ten=new Mobilephone(10,"东芝",20994);
        phoneList.add(ten);
    }
}